package src.CodeTopSecondPractice;

public class _53 {
    public int maxSubArray(int[] nums) {
        if (nums.length == 1)
            return nums[0];
        int[] arr = new int[nums.length];
        arr[0] = nums[0];
        for (int i = 1 ; i < nums.length ; i++) {
            arr[i] = Math.max(arr[i - 1] + nums[i], nums[i]);
        }
        int maxLen = arr[0];
        for (int i = 0 ; i < arr.length ; i++) {
            maxLen = Math.max(maxLen, arr[i]);
        }
        return maxLen;
    }
}
